#!/bin/bash
# 生成密钥脚本
# author: @sudong
# 使用方法：./generatekey.sh alias

if [ $# -ne 1 ]; then
    printf -- "Please input alias.\n\n"
    exit
fi
echo "输入参数密钥$1\n"
keystoreName="$1.jks"
 echo "$keystoreName"
 echo "$1"
if [ ! -d "./keystore" ]; then
  mkdir ./keystore
fi
keystoreName=`uuidgen |cut -c 1-6`
  keytool -genkeypair -alias $1 -keyalg "RSA"  -keysize 2048 -keypass jiahua123456 -validity 3650 -keystore ./keystore/$1.jks  -storepass jiahua123456 -dname "CN='中国', OU='广东', O='广东', L='广东', ST='广东', C='中国'"
  echo jiahua123456 | keytool -importkeystore -srckeystore ./keystore/$1.jks -destkeystore ./keystore/$1.jks -deststoretype pkcs12

if [ ! -f "./key.properties" ]; then
  touch ./key.properties
fi
# shellcheck disable=SC2129
echo "storePassword=jiahua123456" >> ./key.properties
echo "keyPassword=jiahua123456" >> ./key.properties
echo "keyAlias=$1" >> ./key.properties
echo "storeFile=./keystore/$1.jks" >> ./key.properties